<?php
class Pages extends Controller {
  
    public function index()
	{            

        }
        
       public function links()
	{                       
            $link_id=$this->uri->segment(3);
            $seo_url=$this->uri->segment(4);
            $this->load->model('commonmodel');
            $data['customlinks']=$this->commonmodel->get_customlinks($link_id);
            //print_r($data['customlinks']);//exit;
            $this->load->library('breadcrumb');
            $this->breadcrumb->Breadcrumb();
            $this->breadcrumb->addCrumb($data['customlinks'][0]['title']);
            $data['breadcrumb'] = $this->breadcrumb->makeBread();            
            
            $this->load->library("pagination");
            $config = array();
            $customlinks_id = $data['customlinks'][0]['customlinks_id'];  //($this->uri->segment(3)) ? $this->uri->segment(3) : 'all';
            $page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
            $config["base_url"] = base_url() ."/pages/links/".$link_id.'/'.$seo_url;    //.$this->uri->segment(3)."/".$id_alias."/".$id

            $config["total_rows"] = $this->commonmodel->get_mainmenu_list_count($customlinks_id);

            $config["per_page"] = 5;
            $config["uri_segment"] = 5;
            $config['prev_tag_open'] = '<li id="pagecontroller_prev">';
            $config['prev_tag_close'] = '</li>';
            $config['next_tag_open'] = '<li id="pagecontroller_prev">';
            $config['next_tag_close'] = '</li>';
            $config['cur_tag_open'] = '<li><b>';
            $config['cur_tag_close'] = '</li></b>';
            $config['num_tag_open'] = '<li>';
            $config['num_tag_close'] = '</li>';
            $config['first_tag_open'] = '<li>';
            $config['first_tag_close'] = '</li>';
            $config['last_tag_open'] = '<li>';
            $config['lastm_tag_close'] = '</li>';

            $viewer_suffix='links';
            if($link_id==10){  //if the link is Iteneries, then we send him to a special page (grid view)
            $viewer_suffix='special';
            }
        
            $this->pagination->initialize($config);
            $data["pagination"] = $this->pagination->create_links();        
            $data["mainmenudetailarray"]= $this->commonmodel->get_mainmenu_list($config["per_page"], $page, $customlinks_id);
            $data["link_id"]=$link_id;
            $this->template->set('title', '');
            $this->template->load('template', 'custom'.$viewer_suffix, $data);
            //$this->load->view('home');
        }
        
        public function details()
        {       
            $this->load->model('commonmodel');            
            
            $mainmenu_id = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
            $data["mainmenu_id"]=$mainmenu_id;
            $data["mainmenudetails"]= $this->commonmodel->get_mainmenu_details($mainmenu_id);
            $this->template->set('title', '');            
            $data["cat"]=($this->uri->segment(4)) ? $this->uri->segment(3) : 0;
            $seo_url=$this->commonmodel->get_menulinks('', $data["mainmenudetails"][0]['customlinks_id']);
            $this->load->library('breadcrumb');
            $this->breadcrumb->Breadcrumb(); 
            $this->breadcrumb->addCrumb($data["mainmenudetails"][0]['customlinks_page_text'], base_url()."pages/links/".$data["mainmenudetails"][0]['customlinks_page_id']."/".$seo_url[0]['seo_friendly_url']);
            $this->breadcrumb->addCrumb($data["mainmenudetails"][0]['title']);
            $data['breadcrumb'] = $this->breadcrumb->makeBread();      
            
            $this->template->load('template', 'mainmenu_details', $data);
        }
        
         public function topmenudetails()
        {
            $this->load->model('commonmodel');

            $topmenu_id = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
            $data["topmenudetails"]= $this->commonmodel->get_topmenu_details($topmenu_id);
            $this->template->set('title', '');

            $seo_url=$this->commonmodel->get_menulinks('', $data["topmenudetails"][0]['customlinks_page_id']);
            $this->load->library('breadcrumb');
            $this->breadcrumb->Breadcrumb();
            $this->breadcrumb->addCrumb($data["topmenudetails"][0]['customlinks_page_text'], base_url()."pages/links/".$data["mainmenudetails"][0]['customlinks_page_id']."/".$seo_url[0]['seo_friendly_url']);
            $this->breadcrumb->addCrumb($data["topmenudetails"][0]['title']);
            $data['breadcrumb'] = $this->breadcrumb->makeBread();

            $this->template->load('template', 'topmenu_details', $data);
        }
        function inquiry()
        {
            $this->load->library('validation');
           // $this->load->helper('recaptcha');
            
            $this->load->helper('recaptcha');
            $data=array();
            $this->load->model('commonmodel');
            $mainmenu_id = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
            $data["mainmenu_id"]=$mainmenu_id;
            $data["mainmenudetails"]= $this->commonmodel->get_mainmenu_details($mainmenu_id);
            if($this->input->post("submit"))
            {
                $rules['name'] = 'trim|required';
                $rules['message'] = 'trim|required';
                $rules['email'] = 'trim|required|valid_email|unique[users.email]';
                $rules['recaptcha_challenge_field'] = 'required|recaptcha_matches';
                $this->validation->_error_prefix="<div>";
                $this->validation->_error_suffix="</div>";
                $this->validation->set_rules($rules);
                $fields['name'] = 'name';
                $fields['email'] = 'email';
                $fields['message'] = 'message';
                $fields['recaptcha_challenge_field'] = 'answer to the security question';

                $this->validation->set_fields($fields);

                if ($this->validation->run() == TRUE)
                {
                    if($this->sendinquirymail($data["mainmenudetails"]['title'])){
                        $data["successmessage"]="<div class='success'>Your Inquiry Sent Successfully</div>";
                    }
                    
                    else{
                        $data["successmessage"]="<div class='error'>Email could not be sent! Server Error!</div>";
                    }
                }
                else{
                     $data["errorstring"]=$this->validation->error_string;
                     $data["Ename"]=$this->input->post("name");
                     $data["Emessage"]=$this->input->post("message");
                     $data["Eemail"]=$this->input->post("email");
                }

            }
            $data['recapthcha']=recaptcha();
            $this->template->load('template', 'inquiry', $data);
        }

        function sendinquirymail($title)
        {
            $this->load->library('email');
            $config['mailtype'] = 'html';
            $config['charset'] = 'iso-8859-1';
            $config['wordwrap'] = TRUE;
            $this->email->initialize($config);

            $this->email->from('info@explorersrilanka.com', 'Explorere Sri Lanka');
            $this->email->to('induneth87@gmail.com');
            /*$this->email->cc('another@another-example.com');
            $this->email->bcc('them@their-example.com');*/

            $this->email->subject('Inquiry for submission '.$title);
            $message="";
            $message.= "<label> Name: </label>{$this->input->post("name")}<br>";
            $message.= "<label> Email: </label>{$this->input->post("email")}<br>";
            $message.= "<label> Message: </label>{$this->input->post("message")}<br>";
            $this->email->message($message);
            if($this->email->send()){
                return true;
            }
            else{
                return false;
            }
        }

        public function itenerydetails()
	{                       
            $customlinks_id=$this->uri->segment(3);
            $seo_url=$this->uri->segment(4);
            $this->load->model('commonmodel');
            $data['customlinks']=$this->commonmodel->get_customlinks_iteneries($customlinks_id);
            //print_r($data['customlinks']);//exit;
            $this->load->library('breadcrumb');
            $this->breadcrumb->Breadcrumb();
            $this->breadcrumb->addCrumb($data['customlinks'][0]['title']);
            $data['breadcrumb'] = $this->breadcrumb->makeBread();            
            
            $this->load->library("pagination");
            $config = array();
            $customlinks_id = $data['customlinks'][0]['customlinks_id'];  //($this->uri->segment(3)) ? $this->uri->segment(3) : 'all';
            $page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
            $config["base_url"] = base_url() ."/pages/itenerydetails/".$customlinks_id.'/'.$seo_url;    //.$this->uri->segment(3)."/".$id_alias."/".$id

            $config["total_rows"] = $this->commonmodel->get_mainmenu_list_count($customlinks_id);

            $config["per_page"] = 5;
            $config["uri_segment"] = 5;
            $config['prev_tag_open'] = '<li id="pagecontroller_prev">';
            $config['prev_tag_close'] = '</li>';
            $config['next_tag_open'] = '<li id="pagecontroller_prev">';
            $config['next_tag_close'] = '</li>';
            $config['cur_tag_open'] = '<li><b>';
            $config['cur_tag_close'] = '</li></b>';
            $config['num_tag_open'] = '<li>';
            $config['num_tag_close'] = '</li>';
            $config['first_tag_open'] = '<li>';
            $config['first_tag_close'] = '</li>';
            $config['last_tag_open'] = '<li>';
            $config['lastm_tag_close'] = '</li>';

            $viewer_suffix='links';
            if($customlinks_id==10){  //if the link is Iteneries, then we send him to a special page (grid view)
            //$viewer_suffix='special';
            }
        
            $this->pagination->initialize($config);
            $data["pagination"] = $this->pagination->create_links();        
            $data["mainmenudetailarray"]= $this->commonmodel->get_mainmenu_list($config["per_page"], $page, $customlinks_id);

            $this->template->set('title', '');
            $this->template->load('template', 'customlist_itenery', $data);
            //$this->load->view('home');
        }
        
}
?>
